package edu.sctu.zhengsenwen.month201506.day20150603;

import java.text.SimpleDateFormat;
import java.util.Calendar;


/**
 * Created by user15 on 2015/6/6.
 */
public class TimeStamp {


    public long setTime() {

        Calendar calendar = Calendar.getInstance();             //获取当前时间

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");     //设置时间的格式

        calendar.set(2015, 05, 04, 11, 23, 00);                         //设置的时间为2015年06月04日

        String date = simpleDateFormat.format(calendar.getTime());   //设置的时间


        System.out.println(date);

        System.out.println(calendar.getTimeInMillis());

        return calendar.getTimeInMillis();
    }


    public void getTimeStamp() {

        System.out.println("系统默认时间");

        long date2 = setTime();

        long date1 = System.currentTimeMillis();

        long differ = date1 - date2;


        long nd = 1000 * 24 * 60 * 60;            //一天的毫秒数
        long nh = 1000 * 60 * 60;                   //一小时的毫秒数
        long nm = 1000 * 60;                   //一分钟的毫秒数
        long ns = 1000;                        //一秒钟的毫秒数long diff;try {

        long day = differ / nd;                   //计算差多少天
        long hour = differ % nd / nh;             //计算差多少小时
        long min = differ % nd % nh / nm;                  //计算差多少分钟
        long sec = differ % nd % nh % nm / ns;              //计算差多少秒//输出结果
        long mill = differ % nd % nh % nm % ns;

        System.out.println("此时与2015年6月5日11点23分时间相差：\n" + day + "天" + hour + "小时" + min + "分钟" + sec + "秒"+ mill +"毫秒。");
    }


}
